import { renderTableText, tableSorter, tooltipLength } from '@/utils';
import { Tooltip } from 'antd';
import pageStyles from '@/common/pageLayout.less';
// import { ApplyHomeAPI } from '../common/type';
import { ApplyHomeAPI } from '../common/type';

/**
 * 返回表格配置
 * @param taskType true:待办   false:已办
 * @returns
 */
const getHomeTableColumns = (curRes: Record<string, any>, taskType: boolean, onOptClick: ApplyHomeAPI.IOperationClick) => {
  let columns: Record<string, any>[] = [
    {
      title: '事项名称',
      dataIndex: 'attributes.busi_applyTitle',
      key: 'attributes.busi_applyTitle',
      width: 160,
      visible: 'allTask',
      fixed: 'left',
      sorter: (a: any, b: any) => (a?.attributes.busi_applyTitle > b?.attributes.busi_applyTitle ? 1 : -1),
      render: (text: string | null, record: Record<string, any>) => {
        const showText: string | null = record?.attributes?.busi_applyTitle;
        return (
          <Tooltip title={showText ? tooltipLength(showText, 50) : ''}>
            <span className={pageStyles['over-flow-hidden']}>
              <a
                onClick={() => {
                  onOptClick?.onView(record);
                }}
              >
                {showText ? showText : '--'}
              </a>
            </span>
          </Tooltip>
        );
      },
    },
    {
      title: '类型',
      dataIndex: 'attributes.busi_changeWay',
      key: 'attributes.busi_changeWay',
      width: 100,
      visible: 'allTask',
      sorter: (a: any, b: any) => (a?.attributes.busi_changeWay > b?.attributes.busi_changeWay ? 1 : -1),
      render: (text: string | null, record: Record<string, any>) => {
        const changeWay: string | null = record?.attributes.busi_changeWay;
        let showText: string = '采购申请';
        return (
          <Tooltip title={showText ? tooltipLength(showText, 50) : ''}>
            <span className={pageStyles['over-flow-hidden']}>{showText ? showText : '--'}</span>
          </Tooltip>
        );
      },
    },
    {
      title: '当前环节',
      dataIndex: 'taskName',
      key: 'taskName',
      visible: 'allTask',
      width: 170,
      sorter: (a: any, b: any) => tableSorter(a, b, 'taskName'),
      render: (text: string) => renderTableText(text, true),
    },
    {
      title: '时间',
      dataIndex: 'createTime',
      key: 'createTime',
      width: 160,
      visible: 'notTask',
      sorter: (a: any, b: any) => tableSorter(a, b, 'createTime'),
      render: (text: string, record: Record<string, any>) => {
        return (
          <Tooltip title={text ? text : ''}>
            <span className={pageStyles['over-flow-hidden']}>{text ? text : '--'}</span>
          </Tooltip>
        );
      },
    },
    {
      title: '发送人',
      dataIndex: 'attributes.busi_applyerName',
      key: 'attributes.busi_applyerName',
      width: 100,
      visible: 'notTask',
      sorter: (a: any, b: any) => (a?.attributes.busi_applyerName > b?.attributes.busi_applyerName ? 1 : -1),
      render: (text: string | null, record: Record<string, any>) => {
        const showText: string | null = record?.attributes.busi_applyerName;
        return (
          <Tooltip title={showText ? tooltipLength(showText, 50) : ''}>
            <span className={pageStyles['over-flow-hidden']}>{showText ? showText : '--'}</span>
          </Tooltip>
        );
      },
    },
    {
      title: '办理时间',
      dataIndex: 'endTime',
      key: 'endTime',
      width: 160,
      visible: 'handTask',
      sorter: (a: any, b: any) => tableSorter(a, b, 'endTime'),
      render: (text: string, record: Record<string, any>) => {
        return (
          <Tooltip title={text ? text : ''}>
            <span className={pageStyles['over-flow-hidden']}>{text ? text : '--'}</span>
          </Tooltip>
        );
      },
    },
    {
      title: '办理人',
      dataIndex: 'assigneeName',
      key: 'assigneeName',
      width: 100,
      visible: 'handTask',
      sorter: (a: any, b: any) => (a?.assigneeName > b?.assigneeName ? 1 : -1),
      render: (text: string) => renderTableText(text, true),
    },
    {
      title: '办理结果',
      dataIndex: 'resultInfo',
      key: 'resultInfo',
      width: 115,
      visible: 'handTask',
      sorter: (a: any, b: any) => (a?.resultInfo > b?.resultInfo ? 1 : -1),
      render: (text: string) => renderTableText(text, true),
    },
    // {
    //   title: '操作',
    //   dataIndex: 'operation',
    //   key: 'operation',
    //   width: 90,
    //   visible: true,
    //   fixed: 'right',
    //   render: (_text: any, record: any) => {
    //     return (
    //       <div
    //         style={{
    //           display: 'flex',
    //         }}
    //       >
    //         {curRes?.['/contractController/complete'] && record?.assigneeID == getUserID() && record.suspendState == 1 && taskType ? (
    //           <Button
    //             className="manageBtntTxtStyle"
    //             onClick={() => {
    //               onOptClick?.onHand(record);
    //             }}
    //             type={'link'}
    //             size={'smallTask'}
    //             icon={<ProjectOutlined />}
    //           >
    //             办理
    //           </Button>
    //         ) : (
    //           <span style={{ cursor: 'no-drop' }}>--</span>
    //         )}
    //       </div>
    //     );
    //   },
    // },
  ];

  columns = columns?.filter((item: any) => (taskType ? item?.visible != 'handTask' : item?.visible != 'notTask'));

  return columns;
};

export { getHomeTableColumns };
